5 hovzer
= $.getFootHovzer();
7 OO
.ui
.getViewportSpacing = function () {
11 bottom
: hovzer
.$.outerHeight(),
19 * Enabled server-side through `$wgDebugToolbar`.
23 * @author John Du Hart
28 * Toolbar container element
35 * Object containing data for the debug toolbar
42 * Initialize the debugging pane
44 * Shouldn't be called before the document is ready
45 * (since it binds to elements on the page).
47 * @param {Object} [data] Defaults to 'debugInfo' from mw.config
49 init: function ( data
) {
51 this.data
= data
|| mw
.config
.get( 'debugInfo' );
54 // Insert the container into the DOM
55 hovzer
.$.append( this.$container
);
58 $( '.mw-debug-panelink' ).click( this.switchPane
);
62 * Switch between panes
64 * Should be called with an HTMLElement as its thisArg,
65 * because it's meant to be an event handler.
67 * TODO: Store cookie for last pane open.
69 * @param {jQuery.Event} e
71 switchPane: function ( e
) {
72 var currentPaneId
= debug
.$container
.data( 'currentPane' ),
73 requestedPaneId
= $( this ).prop( 'id' ).slice( 9 ),
74 $currentPane
= $( '#mw-debug-pane-' + currentPaneId
),
75 $requestedPane
= $( '#mw-debug-pane-' + requestedPaneId
),
78 function updateHov() {
85 // Skip hash fragment handling. Prevents screen from jumping.
88 $( this ).addClass( 'current ' );
89 $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ' );
91 // Hide the current pane
92 if ( requestedPaneId
=== currentPaneId
) {
93 $currentPane
.slideUp( updateHov
);
94 debug
.$container
.data( 'currentPane', null );
98 debug
.$container
.data( 'currentPane', requestedPaneId
);
100 if ( currentPaneId
=== undefined || currentPaneId
=== null ) {
101 $requestedPane
.slideDown( updateHov
);
104 $requestedPane
.show();
110 * Construct the HTML for the debugging toolbar
112 buildHtml: function () {
113 var $container
, $bits
, panes
, id
, gitInfo
;
115 $container
= $( '<div id="mw-debug-toolbar" class="mw-debug" lang="en" dir="ltr"></div>' );
117 $bits
= $( '<div class="mw-debug-bits"></div>' );
120 * Returns a jQuery element for a debug-bit div
126 function bitDiv( id
) {
127 return $( '<div>' ).prop( {
128 id
: 'mw-debug-' + id
,
129 className
: 'mw-debug-bit'
130 } ).appendTo( $bits
);
134 * Returns a jQuery element for a pane link
138 * @param {string} text
141 function paneLabel( id
, text
) {
144 className
: 'mw-debug-panelabel',
145 href
: '#mw-debug-pane-' + id
151 * Returns a jQuery element for a debug-bit div with a for a pane link
154 * @param {string} id CSS id snippet. Will be prefixed with 'mw-debug-'
155 * @param {string} text Text to show
156 * @param {string} count Optional count to show
159 function paneTriggerBitDiv( id
, text
, count
) {
161 text
= text
+ ' (' + count
+ ')';
163 return $( '<div>' ).prop( {
164 id
: 'mw-debug-' + id
,
165 className
: 'mw-debug-bit mw-debug-panelink'
167 .append( paneLabel( id
, text
) )
171 paneTriggerBitDiv( 'console', 'Console', this.data
.log
.length
);
173 paneTriggerBitDiv( 'querylist', 'Queries', this.data
.queries
.length
);
175 paneTriggerBitDiv( 'debuglog', 'Debug log', this.data
.debugLog
.length
);
177 paneTriggerBitDiv( 'request', 'Request' );
179 paneTriggerBitDiv( 'includes', 'PHP includes', this.data
.includes
.length
);
182 if ( this.data
.gitRevision
!== false ) {
183 gitInfo
= '(' + this.data
.gitRevision
.slice( 0, 7 ) + ')';
184 if ( this.data
.gitViewUrl
!== false ) {
186 .attr( 'href', this.data
.gitViewUrl
)
191 bitDiv( 'mwversion' )
192 .append( $( '<a href="//www.mediawiki.org/">MediaWiki</a>' ) )
193 .append( document
.createTextNode( ': ' + this.data
.mwVersion
+ ' ' ) )
196 if ( this.data
.gitBranch
!== false ) {
197 bitDiv( 'gitbranch' ).text( 'Git branch: ' + this.data
.gitBranch
);
200 bitDiv( 'phpversion' )
201 .append( $( this.data
.phpEngine
=== 'HHVM' ?
202 '<a href="https://hhvm.com/">HHVM</a>' :
203 '<a href="https://php.net/">PHP</a>'
205 .append( ': ' + this.data
.phpVersion
);
208 .text( 'Time: ' + this.data
.time
.toFixed( 5 ) );
211 .text( 'Memory: ' + this.data
.memory
+ ' (Peak: ' + this.data
.memoryPeak
+ ')' );
213 $bits
.appendTo( $container
);
216 console
: this.buildConsoleTable(),
217 querylist
: this.buildQueryTable(),
218 debuglog
: this.buildDebugLogTable(),
219 request
: this.buildRequestPane(),
220 includes
: this.buildIncludesPane()
223 for ( id
in panes
) {
226 className
: 'mw-debug-pane',
227 id
: 'mw-debug-pane-' + id
229 .append( panes
[ id
] )
230 .appendTo( $container
);
233 this.$container
= $container
;
237 * Build the console panel
239 * @return {jQuery} Console panel
241 buildConsoleTable: function () {
242 var $table
, entryTypeText
, i
, length
, entry
;
244 $table
= $( '<table id="mw-debug-console">' );
246 $( '<colgroup>' ).css( 'width', /* padding = */ 20 + ( 10 * /* fontSize = */ 11 ) ).appendTo( $table
);
247 $( '<colgroup>' ).appendTo( $table
);
248 $( '<colgroup>' ).css( 'width', 350 ).appendTo( $table
);
250 entryTypeText = function ( entryType
) {
251 switch ( entryType
) {
263 for ( i
= 0, length
= this.data
.log
.length
; i
< length
; i
+= 1 ) {
264 entry
= this.data
.log
[ i
];
265 entry
.typeText
= entryTypeText( entry
.type
);
269 .text( entry
.typeText
)
270 .addClass( 'mw-debug-console-' + entry
.type
)
272 .append( $( '<td>' ).html( entry
.msg
) )
273 .append( $( '<td>' ).text( entry
.caller
) )
281 * Build query list pane
285 buildQueryTable: function () {
286 var $table
, i
, length
, query
;
288 $table
= $( '<table id="mw-debug-querylist"></table>' );
291 .append( $( '<th>#</th>' ).css( 'width', '4em' ) )
292 .append( $( '<th>SQL</th>' ) )
293 .append( $( '<th>Time</th>' ).css( 'width', '8em' ) )
294 .append( $( '<th>Call</th>' ).css( 'width', '18em' ) )
297 for ( i
= 0, length
= this.data
.queries
.length
; i
< length
; i
+= 1 ) {
298 query
= this.data
.queries
[ i
];
301 .append( $( '<td>' ).text( i
+ 1 ) )
302 .append( $( '<td>' ).text( query
.sql
) )
303 .append( $( '<td class="stats">' ).text( ( query
.time
* 1000 ).toFixed( 4 ) + 'ms' ) )
304 .append( $( '<td>' ).text( query
[ 'function' ] ) )
312 * Build legacy debug log pane
316 buildDebugLogTable: function () {
317 var $list
, i
, length
, line
;
320 for ( i
= 0, length
= this.data
.debugLog
.length
; i
< length
; i
+= 1 ) {
321 line
= this.data
.debugLog
[ i
];
323 .html( mw
.html
.escape( line
).replace( /\n/g, '<br />\n' ) )
331 * Build request information pane
335 buildRequestPane: function () {
337 function buildTable( title
, data
) {
338 var $unit
, $table
, key
;
340 $unit
= $( '<div>' ).append( $( '<h2>' ).text( title
) );
342 $table
= $( '<table>' ).appendTo( $unit
);
345 .html( '<th>Key</th><th>Value</th>' )
348 for ( key
in data
) {
350 .append( $( '<th>' ).text( key
) )
351 .append( $( '<td>' ).text( data
[ key
] ) )
359 .text( this.data
.request
.method
+ ' ' + this.data
.request
.url
)
360 .append( buildTable( 'Headers', this.data
.request
.headers
) )
361 .append( buildTable( 'Parameters', this.data
.request
.params
) );
365 * Build included files pane
369 buildIncludesPane: function () {
370 var $table
, i
, length
, file
;
372 $table
= $( '<table>' );
374 for ( i
= 0, length
= this.data
.includes
.length
; i
< length
; i
+= 1 ) {
375 file
= this.data
.includes
[ i
];
377 .append( $( '<td>' ).text( file
.name
) )
378 .append( $( '<td class="nr">' ).text( file
.size
) )
390 }( mediaWiki
, jQuery
) );